package com.ltf.controller.adm;

import com.ltf.entity.Clz;
import com.ltf.entity.XJson;
import com.ltf.service.ClzService;
import com.ltf.utils.PackJson;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

//班级管理
@RestController
@RequestMapping("/api/adm/clz")
public class ClzController {
    @Autowired
    ClzService clzService;
    //打印输出换成这个
    private Logger logger=LoggerFactory.getLogger(this.getClass());
    public ClzController(){
    }
    //显示所有班级信息
    @GetMapping("/findAll")
    public XJson findAll(){
        List<Clz> clzs = this.clzService.findAll();
        logger.debug(clzs.toString());
        return PackJson.packX(200,"",clzs);
    }

    //单个查
    @PostMapping("/findOne")
    public XJson findOne(String clzno){
        //前端传来的值
        logger.debug(clzno);
        Clz clz =this.clzService.findOne(clzno);
        logger.debug(clz.toString());
        return PackJson.packX(200,"",clz);
    }

    //添加
    @PostMapping("/add")
    public XJson add(Clz clz){
            logger.debug(clz.toString());
            int add = this.clzService.add(clz);
            List<Clz> clzs = this.clzService.findAll();
            return PackJson.packX(200,"添加成功",clzs);
    }

    //修改
    @PostMapping("/update")
    public XJson update(Clz clz){
        int update = this.clzService.update(clz);
        List<Clz> clzs = this.clzService.findAll();
        return PackJson.packX(200,"修改成功",clzs);
    }

    //删除
    @GetMapping("/del")
    public XJson del(String clzno){
        this.clzService.del(clzno);
        List<Clz> clzs = this.clzService.findAll();
        return PackJson.packX(200,"删除成功",clzs);
    }
}
